/*
 * SecurityException.java
 *
 * Created on July 4, 2005, 11:17 PM
 *
 * To change this basis, choose Tools | Options and locate the basis under
 * the Source Creation and Management node. Right-click the basis and choose
 * Open. You can then make changes to the basis in the Source Editor.
 */

package com.xucia.jsponic.security;

import com.xucia.jsponic.data.Persistable;

/**
 *
 * @author Kris Zyp
 */
public class ObjectAccessDeniedException extends SecurityException {
    public static final int BROWSE = 0;  // TODO: These constants should be combined with PermissionLevel
    public static final int READ = 1;
    public static final int WRITE = 2;
    public static final int APPEND = 3;
    public static final int ACCESS_PERMISSION_LEVEL = 5;
    /** Creates a new instance of SecurityException */
    int requestedAction;
    Persistable data;
    public ObjectAccessDeniedException(Persistable data, int requestedAction) {
        this.data = data;
        this.requestedAction = requestedAction;
    }

    public String getMessage() {
        if (requestedAction == BROWSE)
            return "Access denied to " + data + " you do not have any permission";
        if (requestedAction == READ)
            return "Access denied to " + data + " you do not have read permission";
        if (requestedAction == WRITE)
            return "Writing to " + data + " is not permitted, you do not have write permission";
        if (requestedAction == APPEND)
            return "Appending to " + data + " is not permitted, you do not have append permission";
        if (requestedAction == ACCESS_PERMISSION_LEVEL)
            return "Access denied to the permissions for " + data + " you do not have access to the permissions";
        return "Unknown security exception";
    }

}
